﻿@{
    ViewBag.MainMenu = "Settings";
    ViewBag.LeftMenu = "AutoReply";

    ViewBag.Title = "自动回复";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<script language="javascript">

    $(document).ready(function ()
    {
        loadData();
    });

    function loadData()
    {
        var loadLayerIndex = layer.load(0, {
            shade: [0.2, '#fff']
        });

        $.ajax({
            url: "/Api/Settings/GetAutoReplyOnKeyWordsRuleList",
            type: "POST",
            dataType: "json",
            success: function (data, status, jqXHR)
            {
                // alert(data);

                layer.close(loadLayerIndex);
                if (data.Success)
                {
                    var resultObj = data.Data;

                    //  alert(JSON.stringify(resultObj));
                    var gettpl = document.getElementById('divRuleListTemplate').innerHTML;
                    laytpl(gettpl).render(resultObj, function (html)
                    {
                        document.getElementById('divRuleList').innerHTML = html;
                    });

                } else
                {
                    layerAlert(data.Message);
                }
            },
            error: function (xmlHttpRequest)
            {
                layer.close(loadLayerIndex);
                alert("Error: " + xmlHttpRequest.status);
            }
        });
    }

    function modify(id)
    {
        var url = "/Settings/AutoReplyOnKeywordsRule?id=" + id;
        window.location.href = url;
    }

</script>

<script id="divRuleListTemplate" type="text/html">

    {{# for(var i = 0, len = d.length; i < len; i++){ }}

    <div class="divBorder_gray" style=" margin-top:20px;">
        <div style="background-color:#F5F5F8; padding-left:25px; padding-top:10px; padding-bottom:10px;">
            <a href="javascript:void(0)" onclick="modify('{{ d[i].Id }}')">{{ d[i].RuleName }}</a>
        </div>
        <div style="margin-top:10px; margin-bottom:10px;">
            <table width="94%" border="0" align="center" cellpadding="4" cellspacing="0">
                <tr>
                    <td width="100">关键字：</td>
                    <td>
                        <div>
                            {{# for(var k = 0, lenk =  d[i].KeywordList.length; k < lenk; k++){ }}
                            <div style="float:left; background-color:#eeeeee">{{ d[i].KeywordList[k].Keyword }}</div>
                            <div style="float:left;">，</div>
                            {{# } }}
                        </div>
                    </td>
                </tr>
                <tr>
                    <td>回复：</td>
                    <td>{{ d[i].ContentDigest }}</td>
                </tr>
               
                <tr>
                    <td>&nbsp;</td>
                    <td>{{# if(d[i].ReplyAll == true){ }}回复全部{{# }else{ }}随机回复一条{{# } }}</td>
                </tr>
                
            </table>

        </div>

    </div>

    {{# } }}

</script>


<div id="divContentTips">
    公众号收到会员的消息后，首先在此查找匹配的回复内容并将其回复给会员。
</div>


<div style=" margin-top:20px;">
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
            <td class="td_ContentTab" style="width:200px;"><a href="/Settings/AutoReplyOnSubscribe" class="a_black_16">被添加自动回复</a></td>
            <td class="td_ContentTab" style="width:200px;"><a href="/Settings/AutoReplyOnMessage" class="a_black_16">消息自动回复</a></td>
            <td class="td_ContentTab_active" style="width:200px;">关键词自动回复</td>
            <td>&nbsp;</td>
        </tr>
        <tr>
            <td colspan="4" bgcolor="#EEEEEE" height="2"></td>
        </tr>
    </table>
</div>

<div style="margin-left:20px; margin-right:20px;">

    <div style=" margin-top:15px;">
        <input name="btnCreate" type="button" class="btn_blue" id="btnCreate" value="添加规则" onclick="goUrl('/Settings/AutoReplyOnKeywordsRule')" />
    </div>

    <div id="divRuleList">



    </div>

</div>


